package com.smart.campus.web.controller.school;

import java.util.List;

import com.smart.campus.school.domain.PersonnelInfo;
import com.smart.campus.school.service.IPersonnelInfoService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.smart.campus.common.annotation.Log;
import com.smart.campus.common.enums.BusinessType;
import com.smart.campus.school.domain.AwardsAndPunishmentRecord;
import com.smart.campus.school.service.IAwardsAndPunishmentRecordService;
import com.smart.campus.common.core.controller.BaseController;
import com.smart.campus.common.core.domain.AjaxResult;
import com.smart.campus.common.utils.poi.ExcelUtil;
import com.smart.campus.common.core.page.TableDataInfo;

/**
 * 教职工奖惩记录Controller
 * 
 * @author Zhihe.Li
 * @date 2020-06-01
 */
@Controller
@RequestMapping("/school")
public class AwardsAndPunishmentRecordController extends BaseController
{
    private String prefix = "school/awardsinfo";

    @Autowired
    private IAwardsAndPunishmentRecordService awardsAndPunishmentRecordService;

    @Autowired
    private IPersonnelInfoService personnelInfoService;

    //奖励
    @RequiresPermissions("school:awardsinfo:view")
    @GetMapping("/awardsinfo/{userId}")
    public String awardsinfo(@PathVariable("userId") Long userId,ModelMap mmap)
    {
        PersonnelInfo info = personnelInfoService.selectUserById(userId);
        mmap.put("user",info);
        return prefix + "/awardsinfo/awardsinfo";
    }

    //处分列表
    @RequiresPermissions("school:punishment:view")
    @GetMapping("/punishment/{userId}")
    public String punishment(@PathVariable("userId") Long userId,ModelMap mmap)
    {
        PersonnelInfo info = personnelInfoService.selectUserById(userId);
        mmap.put("user",info);
        return prefix + "/punishment/punishment";
    }

    /**
     * 查询教职工奖惩记录列表
     */
    @RequiresPermissions("school:awardsinfo:list")
    @PostMapping("/awardsinfo/list")
    @ResponseBody
    public TableDataInfo list(AwardsAndPunishmentRecord awardsAndPunishmentRecord)
    {
        startPage();
        List<AwardsAndPunishmentRecord> list = awardsAndPunishmentRecordService.selectAwardsAndPunishmentRecordList(awardsAndPunishmentRecord);
        return getDataTable(list);
    }

    /**
     * 查询教职工奖惩记录列表
     */
    @RequiresPermissions("school:punishment:list")
    @PostMapping("/punishment/list")
    @ResponseBody
    public TableDataInfo list2(AwardsAndPunishmentRecord awardsAndPunishmentRecord)
    {
        return list(awardsAndPunishmentRecord);
    }

    /**
     * 导出教职工奖惩记录列表
     */
    @RequiresPermissions("school:awardsinfo:export")
    @Log(title = "教职工奖惩记录", businessType = BusinessType.EXPORT)
    @PostMapping("/awardsinfo/export")
    @ResponseBody
    public AjaxResult export(AwardsAndPunishmentRecord awardsAndPunishmentRecord)
    {
        List<AwardsAndPunishmentRecord> list = awardsAndPunishmentRecordService.selectAwardsAndPunishmentRecordList(awardsAndPunishmentRecord);
        ExcelUtil<AwardsAndPunishmentRecord> util = new ExcelUtil<AwardsAndPunishmentRecord>(AwardsAndPunishmentRecord.class);
        return util.exportExcel(list, "awardsinfo");
    }

    /**
     * 导出教职工奖惩记录列表
     */
    @RequiresPermissions("school:punishment:export")
    @Log(title = "教职工奖惩记录", businessType = BusinessType.EXPORT)
    @PostMapping("/punishment/export")
    @ResponseBody
    public AjaxResult export2(AwardsAndPunishmentRecord awardsAndPunishmentRecord)
    {
        return export(awardsAndPunishmentRecord);
    }

    /**
     * 新增教职工奖惩记录
     */
    @GetMapping("/awardsinfo/add/{userId}")
    public String add(@PathVariable("userId") Long userId,ModelMap mmap)
    {
        PersonnelInfo info = personnelInfoService.selectUserById(userId);
        mmap.put("user",info);
        return prefix + "/awardsinfo/add";
    }

    /**
     * 新增教职工奖惩记录
     */
    @GetMapping("/punishment/add/{userId}")
    public String add2(@PathVariable("userId") Long userId,ModelMap mmap)
    {
        PersonnelInfo info = personnelInfoService.selectUserById(userId);
        mmap.put("user",info);
        return prefix + "/punishment/add";
    }

    /**
     * 新增保存教职工奖惩记录
     */
    @RequiresPermissions("school:awardsinfo:add")
    @Log(title = "教职工奖惩记录", businessType = BusinessType.INSERT)
    @PostMapping("/awardsinfo/add")
    @ResponseBody
    public AjaxResult addSave(AwardsAndPunishmentRecord awardsAndPunishmentRecord)
    {
        return toAjax(awardsAndPunishmentRecordService.insertAwardsAndPunishmentRecord(awardsAndPunishmentRecord));
    }

    /**
     * 新增保存教职工奖惩记录
     */
    @RequiresPermissions("school:punishment:add")
    @Log(title = "教职工奖惩记录", businessType = BusinessType.INSERT)
    @PostMapping("/punishment/add")
    @ResponseBody
    public AjaxResult addSave2(AwardsAndPunishmentRecord awardsAndPunishmentRecord)
    {
        return addSave(awardsAndPunishmentRecord);
    }

    /**
     * 修改教职工奖惩记录
     */
    @GetMapping("/awardsinfo/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        AwardsAndPunishmentRecord awardsAndPunishmentRecord = awardsAndPunishmentRecordService.selectAwardsAndPunishmentRecordById(id);
        mmap.put("awardsAndPunishmentRecord", awardsAndPunishmentRecord);
        PersonnelInfo info = personnelInfoService.selectUserById(awardsAndPunishmentRecord.getUserId());
        mmap.put("user",info);
        return prefix + "/awardsinfo/edit";
    }

    /**
     * 修改保存教职工奖惩记录
     */
    @RequiresPermissions("school:awardsinfo:edit")
    @Log(title = "教职工奖惩记录", businessType = BusinessType.UPDATE)
    @PostMapping("/awardsinfo/edit")
    @ResponseBody
    public AjaxResult editSave(AwardsAndPunishmentRecord awardsAndPunishmentRecord)
    {
        return toAjax(awardsAndPunishmentRecordService.updateAwardsAndPunishmentRecord(awardsAndPunishmentRecord));
    }

    /**
     * 修改教职工奖惩记录
     */
    @GetMapping("/punishment/edit/{id}")
    public String edit2(@PathVariable("id") Long id, ModelMap mmap)
    {
        AwardsAndPunishmentRecord awardsAndPunishmentRecord = awardsAndPunishmentRecordService.selectAwardsAndPunishmentRecordById(id);
        mmap.put("awardsAndPunishmentRecord", awardsAndPunishmentRecord);
        PersonnelInfo info = personnelInfoService.selectUserById(awardsAndPunishmentRecord.getUserId());
        mmap.put("user",info);
        return prefix + "/punishment/edit";
    }

    /**
     * 修改保存教职工奖惩记录
     */
    @RequiresPermissions("school:punishment:edit")
    @Log(title = "教职工奖惩记录", businessType = BusinessType.UPDATE)
    @PostMapping("/punishment/edit")
    @ResponseBody
    public AjaxResult editSave2(AwardsAndPunishmentRecord awardsAndPunishmentRecord)
    {
        return editSave(awardsAndPunishmentRecord);
    }
    /**
     * 删除教职工奖惩记录
     */
    @RequiresPermissions("school:awardsinfo:remove")
    @Log(title = "教职工奖惩记录", businessType = BusinessType.DELETE)
    @PostMapping( "/awardsinfo/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(awardsAndPunishmentRecordService.deleteAwardsAndPunishmentRecordByIds(ids));
    }

    /**
     * 删除教职工奖惩记录
     */
    @RequiresPermissions("school:punishment:remove")
    @Log(title = "教职工奖惩记录", businessType = BusinessType.DELETE)
    @PostMapping( "/punishment/remove")
    @ResponseBody
    public AjaxResult remove2(String ids)
    {
        return remove(ids);
    }
}
